<template>
	<view>
		<view class="cu-bar">
			<view class="action">
				<text @click="clearClick">{{$t('book.qkall')}}</text>
			</view>
			
		</view>
		
		<checkbox-group class="block" @change="CheckboxChange">
			<view class="cu-form-group" v-for="(item,index) in DataList" :key="index">
				<view class="title">{{item.title+' '+item.data.author}}</view>
				<checkbox class="red" :class="item.checked?'checked':''" :checked="item.checked?true:false" :value="item.id"></checkbox>
			</view>
		</checkbox-group>
		
		<view class="cu-tabbar-height margin-bottom"></view>
		
		<view class="padding-left padding-right zai-tabbar-bar" v-if="delArr.length===0">
			<!-- <button class="cu-btn block line-red margin-tb-sm lg" disabled>删除选中</button> -->
		</view>
		
		<view class="padding-left padding-right flex flex-direction zai-tabbar-bar" v-else>
			<button class="cu-btn bg-red margin-tb-sm lg" @click="DelClick">{{$t('book.del')}}({{delArr.length}})</button>
		</view>
		<view class="iconfont booklist" v-if="DataList.length===0 ">
			<text style="font-size:60rpx;">&#xe605;</text>
			<text>{{$t('book.all')}}</text>
		</view>
	</view>
</template>

<script>
	import _tool from '@/util/tools.js';
	import _pc from '@/util/pc.js';
	export default {
		data() {
			return {
				DataList: [], delArr: [],
			}
		},
		onLoad() {
			this.GetBookList();
			_pc.system()
		},
		methods: {
			GetBookList() {
				let that = this;
				_tool.GetBookListData().then(function(res) {
					if(res == "" || res == null || res == undefined) {
						console.log(res);
						that.DataList = [];
					} else {
						that.DataList = res;
					}
				});
			},
			BackClick() {
				uni.navigateBack()
			},
			CheckboxChange (e) {
				let DataList = this.DataList, values = e.detail.value;
				this.delArr = values;
				for (let i = 0; i < DataList.length; ++i) {
					const item = DataList[i];
					if(values.includes(DataList.id)){
						this.$set(item,'checked',true)
					}else{
						this.$set(item,'checked',false)
					}
				}
			},
			DelClick() {
				let that = this;
				_tool.DelBookList(this.delArr).then(function(res) {
					that.GetBookList();
				});
			},
			clearClick() {
				let that = this;
				_tool.clearStorage().then(function(res) {
					that.GetBookList();
				});
        uni.showToast({
          title: this.$t('user.allqk'),
          icon: 'none',
          duration: 2000
        });
			}
		}
	}
</script>

<style lang="less">
	
	.booklist {
		display: block;
		text-align: center;
		margin-top: 300rpx;
		color: #555555;
		font-size: 30rpx;
	} 
</style>
